package dao;

import hbt.HbtUtil;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

import bean.OrdenCompraVO;

public class HbtOrdenCompraDao {

	private static SessionFactory sf = null;
	private static HbtOrdenCompraDao instancia = null;

	public static HbtOrdenCompraDao getInstancia() {
		if (instancia == null) {
			sf = HbtUtil.getSessionFactory();
			instancia = new HbtOrdenCompraDao();
		}
		return instancia;
	}

	public void guardarOrdenCompra(OrdenCompraVO ordenCompra) {
		Session session = sf.openSession();
		session.beginTransaction();
		session.persist(ordenCompra);
		session.flush();
		session.getTransaction().commit();
		session.close();
	}

	public OrdenCompraVO obtenerOrdenCompra(OrdenCompraVO oc) {
		Session session = sf.openSession();
		Transaction trans = session.beginTransaction();
		OrdenCompraVO orden = (OrdenCompraVO) session.get(OrdenCompraVO.class,
				oc.getNroOrdenCompra());
		trans.commit();
		session.close();
		return orden;
	}

}
